/*
 * @lc app=leetcode.cn id=6 lang=javascript
 *
 * [6] Z 字形变换
 */

// @lc code=start
/**
 * @param {string} s
 * @param {number} numRows
 * @return {string}
 */
var convert = function (s, numRows) {
  if (numRows < 2) return s;
  let res = Array.from({ length: numRows }, () => "");
  let flag = 1;
  let step = 0;
  for (let i = 0; i < s.length; i++) {
    if (step === 0) flag = 1;
    if (step === numRows - 1) flag = -1;
    res[step] += s[i];
    step = step + flag;
  }
  return res.join("");
};
// @lc code=end
